
getLoad(1);
function getLoad(page) {
    var url = "/app/member/agent/getindexmsg/page/" + page;
    $.post(url, {r: Math.random()}, function (data) {
        if (IsNull(data)) {
            layer.alert("加载失败,请稍后在试...");
            return false;
        } else if (data.status <= 0) {
            layer.alert(data.info);
            return false;
        } else if(data.status == 2){
            layer.alert("由于长时间未操作，请重新登录！",{title:"信息",closeBtn: 0},function () {
                window.close();
                window.opener.location.reload();
            });
        }else {
            var s_value = data.list.m_value;
            for (var key in s_value) {
                var k_value = s_value[key];
                if (k_value < 0) {
                    $("#" + key).addClass("lose").removeClass("win");
                } else {
                    $("#" + key).addClass("win").removeClass("lose");
                }
                $("#" + key).html(k_value);
            }
            var s_notice = data.list.m_notice.m;
            var page = data.list.m_notice.page;
            var shtml = "";
            for (var key in s_notice) {
                var se_obj = s_notice[key];
                shtml += '<li><a href="javascript:void(0);" onclick="getMsg(' + se_obj['nid'] + ')">' + cutString(se_obj['msg'],90) + '</a><span>' + se_obj['add_time'] + '（详情）</span></li>';
            }
            $("#m_notice").html(shtml);

            if (!IsNull(page)) {
                $("#page").show();
                $("#page").html(page);
            }

        }
    }, "json");
}

function getSms(spage) {
    $("#sms_type").val(2);
    $("#message-box").hide();
    $("#conv-table").show();
    var url = "/app/Member/UserInfo/getSmsList/page/" + page;
    $.post(url, {r: Math.random()}, function (data) {
        if (IsNull(data)) {
            layer.alert("加载失败,请稍后在试...");
            return false;
        } else if (data.status <= 0) {
            layer.alert(data.info);
            return false;
        } else {
            var s_notice = data.list.m_notice.m;
            var page = data.list.m_notice.page;
            var shtml = "";
            for (var key in s_notice) {
                var se_obj = s_notice[key];
                var status_info = "未读";
                var color = "conv-warn";
                if (parseInt(se_obj['islook'])) {
                    status_info = "已读";
                    color = "conv-status";
                }
                shtml += '<tr>';
                shtml += '<td>' + se_obj['msg_time'] + '</td>';
                shtml += '<td style="cursor:pointer;" onclick="getSmsOne(' + se_obj['msg_id'] + ',' + spage + ')">' + se_obj['msg_title'] + '</td>';
                shtml += '<td>' + se_obj['msg_from'] + '</td>';
                shtml += '<td><span class="' + color + '">' + status_info + '</span></td>';
                shtml += '<td><a href="javascript:void(0);" onclick="delSmsOne(' + se_obj['msg_id'] + ',' + spage + ')">删 除</a></td>';
                shtml += '</tr>';

            }
            $("#log").html(shtml);

            if (!IsNull(page)) {
                $("#page").html(page);
            }
        }
    }, "json");
}

function delSmsOne(vnum, page) {
    layer.confirm("确定要删除信息吗？",{title:"警告"},function(){
        var surl = "/app/Member/UserInfo/delSmsOne/id/" + vnum;
        $.get(surl, function (data) {
            if (data.status <= 0) {
                alert(data.info);
                return false;
            } else {
                var msg = data.list.msg;
                layer.alert(msg, {icon: 0});
                getLoad(page);
            }
        }, "json");
    },function(e){
        layer.close(e);
    });
}

function getSmsOne(vnum, page) {
    var surl = "/app/Member/UserInfo/getSmsOne/id/" + vnum;
    $.get(surl, function (data) {
        if (data.status <= 0) {
            alert(data.info);
            return false;
        } else {
            var msg = data.list.msg;
            layer.alert(msg, {icon: 0});
            getSms(page);
        }
    }, "json");
}


function getMsg(num) {
    var surl = "/app/Member/UserInfo/noTice/id/" + num;
    $.get(surl, function (data) {
        if (data.status <= 0) {
            alert(data.info);
            return false;
        } else {
            var msg = data.list.msg;
            layer.alert(msg, {icon: 0});
        }
    }, "json");
}

/**
 * 根据长度截取先使用字符串，超长部分追加…
 * str 对象字符串
 * len 目标字节长度
 * 返回值： 处理结果字符串
 */
function cutString(str, len) {
    //length属性读出来的汉字长度为1
    if(str.length*2 <= len) {
        return str;
    }
    var strlen = 0;
    var s = "";
    for(var i = 0;i < str.length; i++) {
        s = s + str.charAt(i);
        if (str.charCodeAt(i) > 128) {
            strlen = strlen + 2;
            if(strlen >= len){
                return s.substring(0,s.length-1) + "...";
            }
        } else {
            strlen = strlen + 1;
            if(strlen >= len){
                return s.substring(0,s.length-2) + "...";
            }
        }
    }
    return s;
}